package com.sk.wordandpdf;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ContentExtractor {
    /**
     * 正则表达式：验证手机号
     */
    public static final String REGEX_MOBILE = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

    /**
     * 正则表达式：手机号
     */
    public static final String MOBILE = "((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}?";

    /**
     * 正则表达式：验证邮箱
     */
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    /**
     * 正则表达式：邮箱
     */
    public static final String EMAIL = "([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}";

    /**
     * 邮箱
     */
    public static String REGEX = "[a-zA-Z0-9_-]+@\\w+\\.[a-z]+(\\.[a-z]+)?";


    /**
     * 姓名
     */
    public static String NAME = "(?<=(姓名[:,：])|(name[:,：]))([\\u4e00-\\u9fa5]|[' ']){2,}";

    public static ExtractorBody extractor(String content) {
        ExtractorBody extractorBody = new ExtractorBody();

        Pattern pemail = Pattern.compile(EMAIL);
        Matcher memail = pemail.matcher(content);
        while (memail.find()) {
            String email = memail.group();
            extractorBody.setEmail(email);
        }


        Pattern pmobile = Pattern.compile(MOBILE);
        Matcher mmobile = pmobile.matcher(content);
        while (mmobile.find()) {
            String mobile = mmobile.group();
            extractorBody.setMobile(mobile);

        }


        //获取名称
        Pattern pname = Pattern.compile(NAME);
        Matcher mname = pname.matcher(content);
        while (mname.find()) {
            String name = mname.group();
            name = name.trim().replaceAll(" ", "");
            extractorBody.setName(name);
        }
        if(extractorBody.getName() == null || Objects.equals(extractorBody.getName(), "")) {

        }
        return extractorBody;
    }


}
